package com.ruoyi.project.relation.inittable;

import com.ruoyi.inittable.domain.TableColumnInfo;
import com.ruoyi.inittable.domain.TableIndexInfo;
import com.ruoyi.inittable.service.ITableBuildInfoService;
import org.shoukaiseki.ruoyi.annotation.TableBuild;

import java.util.List;

import static com.ruoyi.inittable.utils.TableColumnInfoBuilder.column;
import static com.ruoyi.inittable.utils.TableIndexInfoBuilder.index;
import static com.ruoyi.inittable.utils.TableInfoUtils.tableColumns;
import static com.ruoyi.inittable.utils.TableInfoUtils.tableIndexs;

/**
 *
 **/
@TableBuild(name = "one_way_business_relationship", comment = "单向业务关联",version = 1
        ,remark = "business_relationship 是双向关联,方便查询,该表单向关联,不存在 type")
public class OneWayBusinessRelationshipInitTableInfo implements ITableBuildInfoService {


    @Override
    public List<TableColumnInfo> tableColumnInfoList(){
        List<TableColumnInfo> table = tableColumns(
                column("    one_way_business_relationship_id bigint(20) unsigned auto_increment comment '主键' ").primaryKey(),
                column("    source_owner_id         bigint(20) unsigned default 0                 not null comment '来源业务ID',"),
                column("    source_owner_name       varchar(64)         default ''                not null default '' comment '所属业务名称',"),
                column("    target_owner_id         bigint(20) unsigned default 0                 not null comment '业务对应的ID',"),
                column("    target_owner_name       varchar(64)         default ''                not null default '' comment '业务名称',"),
                column("    create_user_id      bigint(20)  unsigned        null comment '创建者',"),
                column("    create_time      datetime            default CURRENT_TIMESTAMP not null comment '更改时间',"),
                column("    update_user_id      bigint(20)  unsigned        null comment '更改者',"),
                column("    update_time      datetime            default CURRENT_TIMESTAMP not null comment '更改时间',"),
                column("    del_flag         char(1)             default '0'               null comment '删除标志（0代表存在 1代表删除）'"),
                null
        );

        return table;
    }

    @Override
    public List<TableIndexInfo> tableIndexInfoList() {
        return tableIndexs(
                index("one_way_business_relationship_source_index").indexColumns("source_owner_id, source_owner_name"),
                null
        );
    }
//
//    @Override
//    public List<TableTriggerInfo> tableTriggerList() {
//        return tableTriggers(triggerName("inventory_bom_rowstamp")
//                .triggerSql("create trigger inventory_bom_rowstamp before update on inventory_bom FOR EACH ROW\n" +
//                        "begin\n" +
//                        "    set @rowstamp= old.rowstamp;\n" +
//                        "    set NEW.rowstamp=@rowstamp+1;\n" +
//                        "end;\n"));
//    }
}